<?php
namespace Home\Controller;

class OrderController extends BaseController {
    public function showlist(){
        $user_id = session('user_id');
        $info = D('Order')->where("order_u_id=$user_id")->select();
        $this->assign('info',$info);
        $this->display();
    }
   function tianjia(){
       $user_id = session('user_id');
       if(!empty($_POST)){
         $order = D('Order');
         $order->order_sn = date('YmdHis',time()).rand(1000, 9999);
         $order->order_create_time = date('YmdHis',time());
         $order->order_amount = $_POST['amount'];
         $order->order_pay_name = $_POST['payment'];
         $order->order_ship_name = $_POST['shipping'];
         $order->order_u_id = $user_id;
         $z = $order->add();
        if($z){
//            $sql = update sw_cat set order_id = $z , c_status=1 where c_user_id = $user_id;
//            $cat = D('Cat')->execute($sql);
          $cat = D('Cat')->where("c_user_id = $user_id and order_id=0")->save(array("order_id"=>$z,"c_status"=>1,));
          $this->success("订单提交成功!",'showlist');
        }else{
            $this->error("订单提交失败!","Cat/jiesuan");
        }         
       }
   }
   function detail($order_id){
       $cat = D('Cat');
       $info = $cat->where("order_id=$order_id")->select();
       $price = $cat->field('sum(c_price)')->where("order_id = $order_id and c_status = 1")->find();
       $this->assign('price',$price);
       $this->assign('info',$info);
       $this->display();
   }
   function pay($order_id){
       $cat = D('Cat');
       $info = $cat->where("order_id=$order_id")->select();
       $price = $cat->field('sum(c_price)')->where("order_id = $order_id and c_status = 1")->find();
       $this->assign('price',$price);
       $this->assign('info',$info);
       $this->display();
   }
   function dopay($order_id){
       $order = D('Order');
       $info = $order->where("order_id = $order_id")->save(array('order_status'=>1));
       if($info){
//           $this->success('支付成功!','showlist');
           $this->redirect('showlist',array(),2,'支付成功!');
       }else{
           $this->redirect('pay',array(),2,'支付失败!');
       }
   }
   function queren($order_id){
        $order = D('Order');
       $info = $order->where("order_id = $order_id")->save(array('order_status'=>3));
       $this->redirect('showlist');
   }
   function remarks($order_id){
      if(!empty($_POST['order_remarks'])){
       $order = D('Order');
      $info = $order->where("order_id = $order_id")->save(array('order_status'=>4,'order_remarks'=>$_POST['order_remarks']));
      $this->redirect('showlist');
      }
      $this->display();
   }
}